package com.doit.demo02;

@SuppressWarnings("all")
public class test03 {
    public static void main(String[] args) {
        int[] arr = {3, 8, 2, 5, 0,5,1,2,3,5,8,41,651,56,51,153,1,5313,51,51,531,53153,1,531,53,53153,5,21,2,4};
        //冒泡排序
        for (int i = arr.length - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        for (int a : arr)
        {
            System.out.print(a+" ");
        }
        System.out.println();
        int in = 531;//要搜索的值
        int min = 0;
        int max = arr.length - 1;
        int mid = (min + max) / 2;
        while(min<=max){
            mid = in > arr[mid] ? ((mid + 1) + max) / 2 : ((mid - 1) + min) / 2;
//            if(in>arr[mid])
//                min = mid +1;
//            else
//                max = mid-1;
//            mid = (min+max)/2;
            if (in == arr[mid]) {
                System.out.println(mid);
                break;
            }
        }
    }
}
